<template>
  <div class="home">
    <HomeIndex @handleCloseToast='handleCloseToast'/>
    <van-overlay class="overlay" v-show="$store.state.imgDisplay" :lock-scroll="false">
      <template v-if="$store.state.imgDisplay">
        <DsOverlay />
      </template>
    </van-overlay>

  </div>
</template>
<script>
import Cookie from '@/utils/cookie'
import getUrlParam from '@/utils/getUrlParam.js'
import HomeIndex from '@/components/home/HomeIndex'
import DsOverlay from "components/home/DsOverlay";
import inobounce from 'inobounce'
import AesGcm from "@/utils/aesgcm";

export default {
  name: 'Home',
  components: {
    DsOverlay,
    HomeIndex
  },
  async created(){
    // 提示加载中，duration为 0 表示不会消失
    this.$toast.loading({
      message:'加载中...',forbidClick:true,loadingType:'spinner',duration:0
    });
    // iphone 手机禁止滑动回弹效果
    if ( navigator.userAgent.includes('iPhone') ){
      inobounce.enable();
    }
    this.initToken();
    // 存储组织结构信息,必须同步执行，后面接口需要前面接口数据
    await this.$store.dispatch("thePartyBranch321/getUserInfo");
    await this.$store.dispatch("thePartyBranch321/getOrg");
    await this.$store.dispatch("thePartyBranch321/getRoles");
  },
  beforeDestroy() {
    inobounce.disable();
  },
  methods: {
    // 获取token
    initToken() {
      const token = getUrlParam("token");
      const mxSsoToken = getUrlParam("mx_sso_token");
      if (token) {
        Cookie.setCookie("aitalk_token_zh", token);
      } else {
        if (!Cookie.getCookie("aitalk_token_zh")) {
          location.replace(AesGcm.decrypt(process.env.VUE_APP_JUMP_URL));
        }
      }
      if (mxSsoToken) {
        localStorage.setItem("mx_sso_token", mxSsoToken);
      }
    },
    // 注册事件，关闭提示
    handleCloseToast(val) {
      this.$toast.clear();
    },
  }
}
</script>
<style scoped>
.home {
  overflow: hidden;
}

.overlay {
  z-index: 2000;
}

</style>
